package com.mkaech.eece411;

import java.rmi.*;
import java.rmi.server.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class ChatClientRegistry extends UnicastRemoteObject implements IChatClientRegistry
{
	Collection<IChatClient> mClients;
	
	public ChatClientRegistry() throws RemoteException
	{
		mClients = new HashSet<IChatClient>();
	}
	
	public void Register(IChatClient chatClient) throws RemoteException
	{
		mClients.add(chatClient);
	}
	
	public void Unregister(IChatClient chatClient) throws RemoteException
	{
		mClients.remove(chatClient);
	}
	
	public void SendMessageToServer(String message) throws RemoteException
	{
		Iterator<IChatClient> it = mClients.iterator();
		while(it.hasNext())
		{
			it.next().SendMessageToClient(message);
		}
	}
}